var express = require('express');
var app = express();
var fs = require('fs');

app.get('/file/:fileName', function(req, res, next) {
 // 实现文件下载
 // var fileName = req.params.fileName;
 var filePath = "D:/test1.png";
 var stats = fs.statSync(filePath);
 if(stats.isFile()){
  res.set({
   'Content-Type': 'application/octet-stream',
   'Content-Disposition': 'attachment; filename='+"test1.png",
   'Content-Length': stats.size
  });
  fs.createReadStream(filePath).pipe(res);
 } else {
  res.end(404);
 }
});

var server = app.listen(8888,function() {
  var host = server.address().address;
  var port = server.address().port;
  console.info('应用实例，访问地址：%s:%s',host,port);
});

